home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / BoxPaint+ - non stereo / sources / BoxPaint_utility.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  3.8 KB  |  161 lines  |  [TEXT/CWIE]

  1. /*  utility.c                                                                            
  2.  
  3.     Nick Thompson
  4.     Michael Bishop - August 21 1996                                                    
  5.     (c)1994-96 Apple computer Inc., All Rights Reserved                                
  6.  
  7. */
  8.  
  9. /* --------------------------------------------------------------------
  10. ** INCLUDES
  11. */
  12. #include    <QuickDraw.h>
  13. #include    <Events.h>
  14.  
  15. #include    <math.h>
  16.  
  17. #include    "BoxPaint_utility.h"
  18.  
  19. #include    "QD3D.h"
  20. #include    "QD3DMath.h"
  21. #include    "QD3DGroup.h"
  22.  
  23.  
  24. /* --------------------------------------------------------------------
  25. ** GLOBAL VARIABLES
  26. */
  27.  
  28.  
  29. /* --------------------------------------------------------------------
  30. ** LOCAL FUNCTION DEFINITIONS
  31. */
  32.  
  33.  
  34. /*    --------------------------------------------------------------------
  35. **    Utility_HiWrd
  36. **    DESCRIPTION
  37. */
  38. short Utility_HiWrd(long aLong)
  39. {
  40.     return    (((aLong) >> 16) & 0xFFFF) ;
  41. }
  42.  
  43. /*    --------------------------------------------------------------------
  44. **    Utility_LoWrd
  45. **    DESCRIPTION
  46. */
  47. short Utility_LoWrd(long aLong)
  48. {
  49.     return    ((aLong) & 0xFFFF) ;
  50.  
  51. }
  52.  
  53. /*    --------------------------------------------------------------------
  54. **    Utility_DebugString
  55. **    Abstract GetMouse Function for Porting
  56. */
  57. void Utility_DebugString(char    *theMessage)
  58. {
  59.     DebugStr((const unsigned char *)theMessage);
  60. }
  61.  
  62.  
  63. /*    --------------------------------------------------------------------
  64. **    Utility_MemoryNew
  65. **    Memory Allocator
  66. */
  67. void *Utility_MemoryNew(long    size)
  68. {
  69.     return NewHandle(size);
  70. }
  71.  
  72. /*    --------------------------------------------------------------------
  73. **    Utility_MemoryDispose
  74. **    Memory Allocator
  75. */
  76. void Utility_MemoryDispose(Handle    theHandle)
  77. {
  78.     DisposeHandle(theHandle);
  79. }
  80.  
  81.  
  82. /*    --------------------------------------------------------------------
  83. **    Utility_MyGetMouse
  84. **    Abstract GetMouse Function for Porting
  85. */
  86. void Utility_MyGetMouse(TQ3Point2D *thePoint)
  87. {
  88.     Point macPoint;
  89.     
  90.     GetMouse(&macPoint);
  91.     
  92. /*    GlobalToLocal(&macPoint);
  93. */    
  94.     thePoint->x = (float)(macPoint.h);
  95.     thePoint->y = (float)(macPoint.v);
  96. }
  97.  
  98. /*    --------------------------------------------------------------------
  99. **    Utility_MyStillDown
  100. **    Abstract StillDown Function for Porting
  101. */
  102. TQ3Boolean    Utility_MyStillDown(void)
  103. {
  104.     return StillDown() ? kQ3True: kQ3False;
  105. }
  106.  
  107. /*    --------------------------------------------------------------------
  108. **    Utility_GetUpVector
  109. **    Returns a default vector that points as much toward the y axis as it can.
  110. **    Expects the vectors to be normalized.
  111. **    At this point, what to do if the forward vector lies on the y axis is a
  112. **    point of thought. Currently, it returns vector pointing down the -Z axis.
  113. */
  114. void    Utility_GetUpVector(const TQ3Vector3D *theForwardVector, TQ3Vector3D *theUpVector)
  115. {
  116.     TQ3Vector3D    theOrthogonalVector,  tempVector, theForwardVectorCopy = *theForwardVector;
  117.     
  118.     if ( (theForwardVectorCopy.x == 0.0) && (theForwardVectorCopy.z == 0.0) ) {
  119.         theUpVector->x = 0.0; theUpVector->y = 0.0; theUpVector->z = -1.0; 
  120.     } else {
  121.  
  122.         Q3Vector3D_Set ( &tempVector, 0.0, 1.0, 0.0 ) ;
  123.         Q3Vector3D_Cross(&tempVector, (const TQ3Vector3D *)&theForwardVectorCopy, &theOrthogonalVector);
  124.         Q3Vector3D_Cross(&theForwardVectorCopy, (const TQ3Vector3D *)&theOrthogonalVector, &tempVector);
  125.         
  126.         Q3Vector3D_Normalize(&tempVector, theUpVector);    
  127.     }
  128. }
  129.  
  130. /*    --------------------------------------------------------------------
  131. **    Utility_GetEnclosingGroup
  132. **    Takes a hit path and returns the group enclosing the leaf of the path
  133. */
  134. TQ3Object    Utility_GetEnclosingGroup(const TQ3HitPath *theHitPath)
  135. {
  136.     long            subGroupDepth;
  137.     TQ3GroupObject    group, subGroup;
  138.     long            i;
  139.  
  140.     if ( theHitPath->depth < 1 ) {
  141.         return NULL;
  142.     }
  143.     
  144.     if ( theHitPath->depth == 1 ) {
  145.         return theHitPath->rootGroup;
  146.     }
  147.     
  148.     subGroupDepth = theHitPath->depth - 1;
  149.     group = theHitPath->rootGroup;
  150.     
  151.     for (i = 0; i < subGroupDepth; i++) {
  152.         if (Q3Group_GetPositionObject(theHitPath->rootGroup, theHitPath->positions[i], &subGroup) == kQ3Success)
  153.         {
  154.             if ( group != theHitPath->rootGroup) {
  155.                 Q3Object_Dispose(group);
  156.             }
  157.             group = subGroup;
  158.         }
  159.     }
  160.     return group;    
  161. }